package cn.yunlang.zhangZhongFei.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import cn.yunlang.zhangZhongFei.entity.ExchangeAward;
import cn.yunlang.zhangZhongFei.service.ExchangeAwardService;
import cn.yunlang.zhangZhongFei.util.JwtUtil;
import cn.yunlang.zhangZhongFei.vo.request.TokenRequest;
import cn.yunlang.zhangZhongFei.vo.response.R;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ExchangeAward")
@Api(tags = "兑奖记录")
public class ExchangeAwardController {

  @Resource private ExchangeAwardService exchangeAwardService;

  @ApiOperation("分页查")
  @GetMapping("/page")
  public R<IPage<ExchangeAward>> page(
      @ApiParam(value = "页码", required = true) @RequestParam Integer pageNo,
      @ApiParam(value = "每页大小", required = true) @RequestParam Integer pageSize,
      @ApiParam(value = "状态（0=待发货，1=已发货，2=已收货）", required = false) @RequestParam(required = false)
          String state,
      @ApiParam(value = "奖品名称", required = false) @RequestParam(required = false) String awardName,
      @RequestBody TokenRequest request) {

    return exchangeAwardService.pageExchangeAward(pageNo, pageSize, Long.valueOf(new JwtUtil().getUserId()), state, awardName);
  }

  @GetMapping("/one")
  @ApiOperation("根据Id查一条")
  public R<ExchangeAward> one(@RequestParam Long exchangeAwardId) {
    return exchangeAwardService.getOne(exchangeAwardId);
  }

  @GetMapping("/send")
  @ApiOperation("发货")
  public R<String> send(@RequestParam Long exchangeAwardId) {
    return exchangeAwardService.send(exchangeAwardId);
  }

  @GetMapping("/recv")
  @ApiOperation("收货")
  public R<String> recv(@RequestParam Long exchangeAwardId) {
    return exchangeAwardService.recv(exchangeAwardId);
  }

  @PostMapping("/add")
  @ApiOperation("新增")
  public R<String> add(
      @RequestBody ExchangeAward exchangeAward) {

    exchangeAward.setUserId(Long.valueOf(new JwtUtil().getUserId()));
    return exchangeAwardService.addExchangeAward(exchangeAward);
  }

  @GetMapping("/delete")
  @ApiOperation("删除")
  public R<String> delete(@RequestParam Long exchangeAwardId) {
    return exchangeAwardService.deleteExchangeAward(exchangeAwardId);
  }

  @PostMapping("/update")
  @ApiOperation("修改")
  public R<String> update(
      @RequestBody ExchangeAward exchangeAward) {

    exchangeAward.setUserId(Long.valueOf(new JwtUtil().getUserId()));
    return exchangeAwardService.updateExchangeAward(exchangeAward);
  }
}
